/************************************************************
  *  * EaseMob CONFIDENTIAL 
  * __________________ 
  * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved. 
  *  
  * NOTICE: All information contained herein is, and remains 
  * the property of EaseMob Technologies. 
  * Dissemination of this information or reproduction of this material 
  * is strictly forbidden unless prior written permission is obtained
  * from EaseMob Technologies.
  */

#import "DXChatBarMoreView.h"

#define CHAT_BUTTON_SIZE 60
#define CHAT_BUTTON_Height 80

#define INSETS 8

@implementation DXChatBarMoreView
{
    UIPageControl*page;

}
- (instancetype)initWithFrame:(CGRect)frame typw:(ChatMoreType)type
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setupSubviewsForType:type];
    }
    return self;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGPoint point=scrollView.contentOffset;
    page.currentPage=(int)fabs(point.x/DeviceWidth);
}

- (void)setupSubviewsForType:(ChatMoreType)type
{
    self.backgroundColor = [UIColor clearColor];
    //220
    UIScrollView *MoreScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, DeviceWidth, 140)];
    [MoreScrollView setContentSize:CGSizeMake(DeviceWidth * (1), 150)];
    MoreScrollView.pagingEnabled = YES;
    MoreScrollView.scrollsToTop = NO;
    MoreScrollView.delegate = self;
    MoreScrollView.backgroundColor = [UIColor whiteColor];
    MoreScrollView.showsHorizontalScrollIndicator = NO;
    MoreScrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:MoreScrollView];
    
//    page = [[UIPageControl alloc]initWithFrame:CGRectMake(0, MoreScrollView.bounds.size.height-25, DeviceWidth, 20)];
//    page.numberOfPages = 1;
//    [self addSubview:page];
//    page.userInteractionEnabled = NO;
//    page.pageIndicatorTintColor = [UIColor grayColor];//未选中的颜色更改
//    page.currentPageIndicatorTintColor = APPCOLOR(1);//选中的颜色更改
    
//    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, MoreScrollView.bounds.size.height-30, DeviceWidth, 1)];
//    line.backgroundColor = UIColorFromRGB(0xfbf7ee);
//    [self addSubview:line];
    
    
    int x;
    int y;
    
    if([Utils cheackConfigurationGiftShop]){
        x = 0 % 4;  // 列数
        y = 0 / 4;  // 行数
        //第一排
        _giftButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
        [_giftButton setImage:[UIImage imageNamed:@"chat_gift_icon"] forState:UIControlStateNormal];
        _giftButton.title.text = @"礼物";
        [_giftButton addTarget:self action:@selector(giftAction) forControlEvents:UIControlEventTouchUpInside];
        [MoreScrollView addSubview:_giftButton];
        
        x = 1 % 4;  // 列数
        y = 1 / 4;  // 行数
        _photoButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
        [_photoButton setImage:[UIImage imageNamed:@"chat_picture_icon"] forState:UIControlStateNormal];
        _photoButton.title.text = @"图片";
        [_photoButton addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside];
        [MoreScrollView addSubview:_photoButton];
        
        
        x = 2 % 4;  // 列数
        y = 2 / 4;  // 行数
        _takePicButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
        [_takePicButton setImage:[UIImage imageNamed:@"chat_paizhao_icon"] forState:UIControlStateNormal];
        _takePicButton.title.text = @"拍照";
        [_takePicButton addTarget:self action:@selector(takePicAction) forControlEvents:UIControlEventTouchUpInside];
        [MoreScrollView addSubview:_takePicButton];
    }else{
        x = 0 % 4;  // 列数
        y = 0 / 4;  // 行数
        
        _photoButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
        [_photoButton setImage:[UIImage imageNamed:@"chat_picture_icon"] forState:UIControlStateNormal];
        _photoButton.title.text = @"图片";
        [_photoButton addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside];
        [MoreScrollView addSubview:_photoButton];
        
        x = 1 % 4;  // 列数
        y = 1 / 4;  // 行数
        _takePicButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
        [_takePicButton setImage:[UIImage imageNamed:@"chat_paizhao_icon"] forState:UIControlStateNormal];
        _takePicButton.title.text = @"拍照";
        [_takePicButton addTarget:self action:@selector(takePicAction) forControlEvents:UIControlEventTouchUpInside];
        [MoreScrollView addSubview:_takePicButton];
    }
    
   

    
//    x = 2 % 4;  // 列数
//    y = 2 / 4;  // 行数
//    _audioCallButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
//    [_audioCallButton setImage:[UIImage imageNamed:@"chat_phone_icon"] forState:UIControlStateNormal];
//    _audioCallButton.title.text = @"打电话";
//    [_audioCallButton addTarget:self action:@selector(takeAudioCallAction) forControlEvents:UIControlEventTouchUpInside];
//    [MoreScrollView addSubview:_audioCallButton];

    /*
    x = 3 % 4;  // 列数
    y = 3 / 4;  // 行数
    _privateMessagesButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
    [_privateMessagesButton setImage:[UIImage imageNamed:@"chat_simi_icon"] forState:UIControlStateNormal];
    _privateMessagesButton.title.text = @"私密消息";
    [_privateMessagesButton addTarget:self action:@selector(privateAction) forControlEvents:UIControlEventTouchUpInside];
    [MoreScrollView addSubview:_privateMessagesButton];


    
    //第二排
    x = 4 % 4;  // 列数
    y = 4 / 4;  // 行数
    _jitterButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
    [_jitterButton setImage:[UIImage imageNamed:@"戳一下"] forState:UIControlStateNormal];
    _jitterButton.title.text = @"戳一下";
    [_jitterButton addTarget:self action:@selector(jitterAction) forControlEvents:UIControlEventTouchUpInside];
    [MoreScrollView addSubview:_jitterButton];
    
    x = 5 % 4;  // 列数
    y = 5 / 4;  // 行数
    _sleepButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
    [_sleepButton setImage:[UIImage imageNamed:@"chat_woshuile_icon"] forState:UIControlStateNormal];
    _sleepButton.title.text = @"我睡了";
    [_sleepButton addTarget:self action:@selector(sleepAction) forControlEvents:UIControlEventTouchUpInside];
    [MoreScrollView addSubview:_sleepButton];
    
    x = 6 % 4;  // 列数
    y = 6 / 4;  // 行数
    _truthButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake((DeviceWidth/25) *(1+6 *x), 10+(10+CHAT_BUTTON_Height) *y, CHAT_BUTTON_SIZE, CHAT_BUTTON_SIZE)];
    [_truthButton setImage:[UIImage imageNamed:@"chat_zhenxinhua_icon"] forState:UIControlStateNormal];
    _truthButton.title.text = @"真心话";
    [_truthButton addTarget:self action:@selector(truthAction) forControlEvents:UIControlEventTouchUpInside];
    [MoreScrollView addSubview:_truthButton];
    
    */
    
    //地理定位
    /*
     _locationButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake(insets * 3 + CHAT_BUTTON_SIZE * 2, 0, CHAT_BUTTON_SIZE , CHAT_BUTTON_SIZE)];
     [_locationButton setImage:[UIImage imageNamed:@"chatBar_colorMore_location"] forState:UIControlStateNormal];
     [_locationButton setImage:[UIImage imageNamed:@"chatBar_colorMore_locationSelected"] forState:UIControlStateHighlighted];
     [_locationButton addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
     [MoreScrollView addSubview:_locationButton];
     */

    
    
    CGRect frame = self.frame;
    if (type == ChatMoreTypeChat) {
        frame.size.height = 100;
        
        /*视频
         _videoButton =[[DXChatBarBtn alloc]initWithFrame:CGRectMake(insets, 2 + CHAT_BUTTON_SIZE-20, CHAT_BUTTON_SIZE , CHAT_BUTTON_SIZE)];
        [_videoButton setImage:[UIImage imageNamed:@"chatBar_colorMore_video"] forState:UIControlStateNormal];
        [_videoButton setImage:[UIImage imageNamed:@"chatBar_colorMore_videoSelected"] forState:UIControlStateHighlighted];
        [_videoButton addTarget:self action:@selector(takeVideoAction) forControlEvents:UIControlEventTouchUpInside];
        [MoreScrollView addSubview:_videoButton];
         */
        
    }
    else if (type == ChatMoreTypeGroupChat)
    {
        frame.size.height = 80;
    }
    self.frame = frame;
}

#pragma mark - action

- (void)takePicAction{
    [AVAnalytics event:[NSString stringWithFormat:@"聊天百宝箱功能"] label:@"拍照"]; //type是变量,表示用户类型
    if(_delegate && [_delegate respondsToSelector:@selector(moreViewTakePicAction:)]){
        [_delegate moreViewTakePicAction:self];
    }
}

- (void)photoAction
{
    [AVAnalytics event:[NSString stringWithFormat:@"聊天百宝箱功能"] label:@"图片"]; //type是变量,表示用户类型
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewPhotoAction:)]) {
        [_delegate moreViewPhotoAction:self];
    }
}
- (void)giftAction
{
    [AVAnalytics event:[NSString stringWithFormat:@"聊天百宝箱功能"] label:@"礼物"]; //type是变量,表示用户类型
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewGiftAction:)]) {
        [_delegate moreViewGiftAction:self];
    }
}

- (void)locationAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewLocationAction:)]) {
        [_delegate moreViewLocationAction:self];
    }
}

- (void)takeVideoAction{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewLocationAction:)]) {
        [_delegate moreViewVideoAction:self];
    }
}

- (void)takeAudioCallAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewAudioCallAction:)]) {
        [_delegate moreViewAudioCallAction:self];
    }
}


/*附加
 */
- (void)privateAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewPrivateMessagesAction:)]) {
        [_delegate moreViewPrivateMessagesAction:self];
    }
}

- (void)jitterAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewJitterAction:)]) {
        [_delegate moreViewJitterAction:self];
    }
}

- (void)sleepAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewSleepAction:)]) {
        [_delegate moreViewSleepAction:self];
    }
}

- (void)truthAction
{
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewTruthAction:)]) {
        [_delegate moreViewTruthAction:self];
    }
}





@end
